 //需要用到的全局变量
var _personName = "";
var _personId = "";
var _newobject_;
/**
人员选择组件方法getUser
参数含义：name，id对应页面里显示和隐藏的元素。
type 是选择人员类型，多选("many")还是单选("single")。
isFilter（true  或者是 false）true就是过滤，false就是不过滤。
*/
function getUser(id, name, type, isFilter) {
	if (window.top.opener.closed == false) {
		var _obj_ = window.top.opener.top.legend;
	} else {
		var _obj_ = window.top.legend;
	}
	
	var userArray = _obj_.userArray;
	var personNameAry = new Array();
	var personIdAry = new Array();
	_personName = document.all[name].value;
	_personId = document.all[id].value;
	if (event.keyCode == 13) {
		if (_personName.indexOf(",") == -1) {
			var patten = new RegExp(_personName);
			for (var i = 0; i < userArray.length; i++) {
				if (userArray[i].name.match(patten)) {
					personNameAry[personNameAry.length] = userArray[i].name;
					personIdAry[personIdAry.length] = userArray[i].id;
				}
			}
			if (personNameAry.length == 1) {
				_personName = personNameAry[0] + ",";
				_personId = personIdAry[0] + ",";
			} else {
				if (personNameAry.length < 1) {
					switch (isFilter) {
					  case false:
						break;
					  case true:
						_personName = "";
						break;
					}
				} else {
					switch (type) {
					  case "many":
						openwindow(personNameAry, personIdAry, "many");
						break;
					  case "single":
						openwindow(personNameAry, personIdAry, "single");
						break;
					}
				}
			}
		} else {
			if (_personName.lastIndexOf(",") != -1) {
				var s = _personName.substring((_personName.lastIndexOf(",") + 1), _personName.length);
				var patten1 = new RegExp(s);
				for (var i = 0; i < userArray.length; i++) {
					if (userArray[i].name.match(patten1)) {
						personNameAry[personNameAry.length] = userArray[i].name;
						personIdAry[personIdAry.length] = userArray[i].id;
					}
				}
				if (personNameAry.length == 1) {
					switch (type) {
					  case "many":
						_personId += personIdAry[0] + ",";
						_personName = _personName.substring(0, _personName.lastIndexOf(",") + 1) + personNameAry[0] + ",";
						break;
					  case "single":
						_personId = personIdAry[0] + ",";
						_personName = personNameAry[0] + ",";
						break;
					}
				} else {
					if (personNameAry.length < 1) {
						switch (isFilter) {
						  case false:
							break;
						  case true:
							_personName = _personName.substring(0, _personName.lastIndexOf(",") + 1);
							break;
						}
					} else {
						switch (type) {
						  case "many":
							openwindow(personNameAry, personIdAry, "many");
							break;
						  case "single":
							openwindow(personNameAry, personIdAry, "single");
							break;
						}
					}
				}
			}
		}
		document.getElementById(name).value = _personName;
		document.getElementById(id).value = _personId;
		document.forms[0].elements[name].focus();
	}
}
/**弹出的窗口此方法会在getUser中调用*/
function openwindow(personNameAry, userIdAry, type) {
	var date = new Date();
	var rnd = date.getTime();
	var height = "400";
	var width = "400";
	var topheight = (window.screen.height - height) / 2;
	var leftwidth = (window.screen.width - width) / 2;
	var url = "sys/personSelect!initPersonSelect.action";
	var obj = new Object();
	//obj.patten =patten;
	obj.nameary = personNameAry;
	obj.idary = userIdAry;
	_newobject_ = obj;
	if (ie) {
		var vReturnValue = window.showModalDialog(url, obj, "dialogHeight: " + height + "px; dialogWidth: 450px; center: Yes; help: no; resizable: no; status: no;");
		if (vReturnValue.id != "-1") {
			switch (type) {
			  case "many":
				_personName = _personName.substring(0, _personName.lastIndexOf(",") + 1) + vReturnValue.name;
				_personId += vReturnValue.id;
				break;
			  case "single":
				_personName = vReturnValue.name.substring(0, vReturnValue.name.length - 1);
				_personId = vReturnValue.id.substring(0, vReturnValue.id.substring.length - 1);
				break;
			}
		}
	} else {
		if (moz) {
			window.open(url, "\u9009\u62e9\u4eba\u5458", "height=" + height + ",width=" + width + ",top=" + topheight + ",left=" + leftwidth + ",alwaysRaised=yes,depended=yes,titlebar=no,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no,z-look=yes");
		}
	}
}

function Person(id,name) {
    this.name = name;
	this.id = id;
}
